package org.autumn.thread;

import java.util.concurrent.TimeUnit;

public class JoinMethod2 {

    private static int res1 = 0;
    private static int res2 = 0;

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            res1 = 10;
        }, "t1");

        Thread t2 = new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            res2 = 20;
        }, "t2");
        long start = System.currentTimeMillis();
        t1.start();
        t2.start();

        t1.join();
        t2.join();
        System.out.println("cost -> " + (System.currentTimeMillis() - start));
        System.out.println("res1 = " + res1);
        System.out.println("res2 = " + res2);

    }
}
